package com.nbicc.dp.modular.exception;

import com.nbicc.core.common.ResponseUtil;
import com.nbicc.core.utils.ExceptionUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.context.request.WebRequest;
import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler;

/**
 * Created by li on 17/12/22.
 * 在执行@RequestMapping时，进入逻辑处理阶段前。譬如传的参数类型错误。
 */
@Slf4j
@ControllerAdvice
public class IntoRequestMappingExceptionHandler extends ResponseEntityExceptionHandler {

    @Override
    protected ResponseEntity<Object> handleExceptionInternal(Exception ex, Object body, HttpHeaders headers, HttpStatus status, WebRequest request) {
        log.error(ExceptionUtil.getStackTraceInfo(ex));
        return super.handleExceptionInternal(ex, ex.getMessage() , headers, status, request);
    }
}
